package com.zxl.live.screen.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.zxl.live.screen.R;
import com.zxl.live.screen.screen.ui.helper.data.SuiScreenDataHelper;
import com.zxl.live.tools.base.BaseAppCompatActivity;
import com.zxl.live.tools.common.ApplicationHelper;
import com.zxl.live.tools.tools.TimeUtils;

/**
 * Created by Administrator on 2017/11/17.
 */

public class SplashActivity extends BaseAppCompatActivity implements Runnable {

    private long startTimer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        startTimer = System.currentTimeMillis();
        ApplicationHelper.postUiThreadDelayed(this, 2000);
    }

    public static void startSplash(Context mContext, SuiScreenDataHelper.DataType dataType, int additional) {
        mContext.startActivity(new Intent(mContext, SplashActivity.class).putExtra("data", dataType).putExtra("additional", additional).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }

    @Override
    public void run() {
        SuiScreenDataHelper.DataType enter = (SuiScreenDataHelper.DataType) getIntent().getSerializableExtra("data");
        if (null != enter) {
            enter.restartPage(this, getIntent().getIntExtra("additional", 0));
        } else {
            ApplicationHelper.postUiThreadDelayed(new Runnable() {
                @Override
                public void run() {
                    startActivity(new Intent(SplashActivity.this, MainActivity.class));
                    finish();
                }
            }, 2 * TimeUtils.SECOND - (System.currentTimeMillis() - startTimer));
        }
    }
}
